package com.itheima.mapper;

import com.itheima.pojo.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    /**
     * 添加地址
     * @param addressBook
     * @return
     */
    void addAddressBook(AddressBook addressBook);

    @Select("select * from address_book where user_id=#{userId}")
    List<AddressBook> list(AddressBook addressBook);

    @Select("select * from address_book where is_default=#{isDefault} and user_id=#{userId}")
    AddressBook getDefaultAddress(AddressBook addressBook);

    @Update("update address_book set is_default=#{isDefault} where user_id=#{userId} and id=#{id}")
    void updateDefault(AddressBook addressBook);
    @Update("update address_book set is_default=#{isDefault} where user_id=#{userId} and id!=#{id}")
    void updateNoDefault(AddressBook addressBook);

    @Select("select * from address_book where id=#{id}")
    AddressBook getById(Long id);
    /**
     * 根据id修改地址
     * @param addressBook
     * @return
     */
    void update(AddressBook addressBook);

    /**
     * 根据地址id删除地址
     * @return
     */
    @Delete("delete from address_book where id=#{id}")
    void deleteById(Long id);
}
